package cn.sumpu.app.guoguojie.biz.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.biz.TWeibo;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.TencentWeibo;

public class TWeiboImpl implements TWeibo {
	private final static Logger logger = LoggerFactory
	.getLogger(TWeiboImpl.class);
	
	private String weiboTencentAppCallBack;
	
	
	

	public void setWeiboTencentAppCallBack(String weiboTencentAppCallBack) {
		this.weiboTencentAppCallBack = weiboTencentAppCallBack;
	}

	@Override
	public String openOauth(String oauthType) throws AppBusinessException {
		try {
			return TencentWeibo.openOauth(weiboTencentAppCallBack,oauthType); 
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("oauth fail", e);
			}
			throw new AppBusinessException(e);
		}
	}

	@Override
	public Map<String, String> oauth(String oauthVerifier,String clientIP,String oauthType)
			throws AppBusinessException {
		try {
			return TencentWeibo.oauth(oauthVerifier, clientIP,weiboTencentAppCallBack,oauthType);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("oauth fail", e);
			}
			throw new AppBusinessException(e);
		}
	}

	@Override
	public void sendMessage(String text, String accessToken, String accessSecret,String clientIP)
			throws AppBusinessException {
		try {
			 TencentWeibo.sendMessage2TencentWeibo(text, accessToken, accessSecret, clientIP);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("sendMessage2TencentWeibo fail", e);
			}
			throw new AppBusinessException(e);
		}

	}

	@Override
	public void cancelAttentionWeibo(String accessToken, String accessSecret)
			throws AppBusinessException {
		try {
			 TencentWeibo.cancelAttentionTencentWeibo(accessToken, accessSecret);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("cancelAttentionTencentWeibo fail", e);
			}
			throw new AppBusinessException(e);
		}

	}

}
